package com.yhgarden.bbs.controller.system;

import com.yhgarden.bbs.entity.system.Role;
import com.yhgarden.bbs.entity.system.UserRole;
import com.yhgarden.bbs.entity.vo.role.UserIdRoleIdsVo;
import com.yhgarden.bbs.model.response.BaseResponse;
import com.yhgarden.bbs.service.api.system.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping(value = {"/system/role","*/system/role"})
public class RoleController {

    @Autowired
    private RoleService roleService;

    @RequestMapping(value = "/createOrUpdate", method = RequestMethod.POST,
            consumes = {"application/json"},
            produces = {"application/json"})
    @ResponseBody
    public BaseResponse createOrUpdate(HttpSession session, @RequestBody Role role) throws Exception {
        BaseResponse res = roleService.createOrUpdate(session, role);
        return res;
    }

    @RequestMapping(value = "/handleUserRole", method = RequestMethod.POST,
            consumes = {"application/json"},
            produces = {"application/json"})
    @ResponseBody
    public BaseResponse handleUserRole( @RequestBody UserIdRoleIdsVo userIdRoleIdsVo) throws Exception {
        BaseResponse res = roleService.handleUserRole(userIdRoleIdsVo);
        return res;
    }

    @RequestMapping(value = "/getById/{roleId}", method = RequestMethod.GET)
    @ResponseBody
    public BaseResponse getById(@PathVariable("roleId") String roleId) {
        BaseResponse res = roleService.getById(roleId);
        return res;
    }

    @RequestMapping(value = "/getByPid/{pid}", method = RequestMethod.GET)
    @ResponseBody
    public BaseResponse getByPid(@PathVariable("pid") String pid) {
        BaseResponse res = roleService.getByPid(pid);
        return res;
    }

    @RequestMapping(value = "/getByUserId/{userId}", method = RequestMethod.GET)
    @ResponseBody
    public BaseResponse getByUserId(@PathVariable("userId") String userId) {
        BaseResponse res = roleService.getByUserId(userId);
        return res;
    }

    @RequestMapping(value = "/getByIdMoreDetail/{roleId}", method = RequestMethod.GET)
    @ResponseBody
    public BaseResponse getByIdMoreDetail(@PathVariable("roleId") String roleId) {
        BaseResponse res = roleService.getByIdMoreDetail(roleId);
        return res;
    }

    @RequestMapping(value = "/query", method = RequestMethod.POST,
            consumes = {"application/json"},
            produces = {"application/json"})
    @ResponseBody
    public BaseResponse query(@RequestBody Role role) {
        BaseResponse res = roleService.query(role);
        return res;
    }

    @RequestMapping(value = "/queryForList", method = RequestMethod.POST,
            consumes = {"application/json"},
            produces = {"application/json"})
    @ResponseBody
    public BaseResponse queryForList(@RequestBody Role role) {
        BaseResponse res = roleService.queryForList(role);
        return res;
    }

    @RequestMapping(value = "/queryMoreDetail", method = RequestMethod.POST,
            consumes = {"application/json"},
            produces = {"application/json"})
    @ResponseBody
    public BaseResponse queryMoreDetail(@RequestBody Role role) {
        BaseResponse res = roleService.queryMoreDetail(role);
        return res;
    }

    @RequestMapping(value = "/delete/{roleId}", method = RequestMethod.POST)
    @ResponseBody
    public BaseResponse delete(@PathVariable("roleId") String roleId) {
        BaseResponse res = roleService.delete(roleId);
        return res;
    }

}
